﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Secams.utils;
using System.Data.OleDb;
using ADODB;
using System.Data;

namespace Secams.controller
{
    class ConfigDao
    {
        public const string TABLENAME = "tblVersion";
        public string _dbFilepath;

        public ConfigDao(string dbFilepath)
        {
            if (dbFilepath != null)
                _dbFilepath = dbFilepath;
            else
                _dbFilepath = "../../data/Secams.mdb";
        }

        public void initialize() {
            using (OleDbConnection dbConn = MdbUtil.getConnection(_dbFilepath))
            {

                if (!MdbUtil.existsTable(dbConn, TABLENAME))
                {
                    //http://www.sulc.edu/sulcalumni/app/lib/pear/docs/MDB/doc/datatypes.html#5.1.3
                    OleDbCommand cmd = dbConn.CreateCommand();
                    cmd.CommandText = "CREATE TABLE " + TABLENAME + " (id TEXT(12)"
                        + ", scenarioOrder INT"
                        + ", scenarioFile TEXT(64)"
                        + ", remark TEXT(64));";

                    cmd.ExecuteNonQuery();
                }
                dbConn.Close();
            }
        }
    }
}
